package com.interview.ujiuye9;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * Copyright (C), 2018-2020
 * FileName: ProxyFactory
 * Author:   kongfanyu
 * Date:     2020/11/11 15:44
 */
public class ProxyFactory {

    private Object target ;//被代理对象

    public ProxyFactory(Object o){
        this.target = o;
    }

    public Object getProxy(){
        InvocationHandler h = new MyLogInvocaitonHandler(target);
        Object proxy = Proxy.newProxyInstance(
                target.getClass().getClassLoader(),  //类加载器
                target.getClass().getInterfaces(),   //目标对象实现的接口
                h                                    //调用处理器
        );
        return proxy;
    }
}
